# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

from jms_hi.dwd.tms.dwd_tmsnew_shipment_union_base_hi import jms_dwd__dwd_tmsnew_shipment_union_base_hi
from jms_hi.dwd.tms.dwd_tmsnew_shipment_stop_union_base_hi import jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_loading_base_hi import jms_dwd__dwd_tab_barscan_loading_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_unloading_base_hi import jms_dwd__dwd_tab_barscan_unloading_base_hi

jms_hi_dm__dm_shipment_stop_billcode_detail_dt  = SparkSqlOperator(
    task_id='jms_hi_dm__dm_shipment_stop_billcode_detail_dt',
    email=['guoruiling@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_hi_dm__dm_shipment_stop_billcode_detail_dt_{{ execution_date | cst_ds }}',
    sql='jms_hi/dm/dm_shipment_stop_billcode_detail_dt/execute.hql',
    pool_slots=1,
    retries=1,
    depends_on_past=True,
    driver_memory='5G' , 
    executor_memory='6G' ,
    executor_cores=4 , 
    num_executors=14 , 
    yarn_queue='pro',
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors'             : 17 ,
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead'             : '2G' ,
          'spark.default.parallelism': 320,
          'spark.sql.shuffle.partitions': 320
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 180,  # -表示一个动态分区语句可以创建的最大动态分区个数，超出报错
              'hive.exec.max.dynamic.partitions.pernode': 180,  # 默认100，一般可以设置大一点，比如1000。表示每个maper或reducer可以允许创建的最大动态分区个数，默认是100，超出则会报错。
              },
    execution_timeout=timedelta(hours=1)
)

jms_hi_dm__dm_shipment_stop_billcode_detail_dt  << [
    jms_dwd__dwd_tmsnew_shipment_union_base_hi,
    jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi,
    jms_dwd__dwd_tab_barscan_loading_base_hi,
    jms_dwd__dwd_tab_barscan_unloading_base_hi,

]
 